package com.lcl.jarvis.admin.modules.person.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.lcl.jarvis.admin.modules.person.dto.request.TbPersonImagesPageReqDTO;
import com.lcl.jarvis.admin.modules.person.dto.request.TbPersonImagesReqDTO;
import com.lcl.jarvis.admin.modules.person.dto.response.TbPersonImagesRespDTO;
import com.lcl.jarvis.admin.modules.person.service.ITbPersonImagesService;
import lombok.RequiredArgsConstructor;
import com.lcl.jarvis.common.model.R;
import com.lcl.jarvis.common.model.PageResult;
import org.springframework.web.multipart.MultipartFile;

/**
 * 人员彩超图片存储Controller
 *
 * @author licl
 * @date 2024-06-26 14:35:51
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/person/personFileImgs")
public class TbPersonImagesController {

    private final ITbPersonImagesService tbPersonImagesService;

    /**
     * 新增人员彩超图片存储
     *
     * @param body
     * @return
     */
    @PostMapping
    public R<Integer> add(@RequestBody TbPersonImagesReqDTO body) {
        return R.succeed(tbPersonImagesService.add(body));
    }

    /**
     *  图片上传接口
     *  上传图片到服务器，并返回图片的url地址
     * @param file
     * @return
     */
    @PostMapping("/uploadImg")
    public R<TbPersonImagesRespDTO> uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("personId") String personId) {
        System.out.println("personId:" + personId);
        TbPersonImagesRespDTO url = tbPersonImagesService.uploadImg(file, personId);
        return R.succeed(url);
    }

    /**
     * 查询图片返回文件流
     * @param personId
     * @return
     */
    @GetMapping("/queryImg/{personId}")
    public R<List<TbPersonImagesRespDTO>> queryImg(@PathVariable String personId) {
        List<TbPersonImagesRespDTO> bytes = tbPersonImagesService.queryImgByPersonId(personId);
        return R.succeed(bytes);
    }

    /**
     * 删除人员彩超图片存储
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable List<String> ids) {
        return R.succeed(tbPersonImagesService.remove(ids));
    }

    /**
     * 修改人员彩超图片存储
     *
     * @param body
     * @return
     */
    @PutMapping
    public R<Integer> update(@RequestBody TbPersonImagesReqDTO body) {
        return R.succeed(tbPersonImagesService.update(body));
    }

    /**
     * 获取人员彩超图片存储详细信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}")
    public R<TbPersonImagesRespDTO> detail(@PathVariable("id") String id) {
        return R.succeed(tbPersonImagesService.detail(id));
    }

    /**
     * 查询人员彩超图片存储列表
     *
     * @param req
     * @return
     */
    @GetMapping("/list")
    public R<PageResult<TbPersonImagesRespDTO>> page(TbPersonImagesPageReqDTO req) {
        return R.succeed(tbPersonImagesService.page(req));
    }

}
